package cn.lcsjsxy.yxc.servlet;

import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;

import java.io.IOException;

@WebServlet(value = "/servletB")
public class ServletB extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取请求域中的数据
        String reqMassage=(String) req.getAttribute("request");
        System.out.println("B请求域："+reqMassage);

        //获取会话域中的数据
        HttpSession session=req.getSession();
        String sessMassage=(String) session.getAttribute("session");
        System.out.println("B会话域："+sessMassage);

        //获取应用域的数据
        ServletContext application=getServletContext();
        String appMassage=(String) application.getAttribute("application");
        System.out.println("B应用域:"+appMassage);
    }
}
